package com.stu.student_back_end.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stu.student_back_end.controller.dto.CountDTO;
import com.stu.student_back_end.controller.dto.PageDTO;
import com.stu.student_back_end.entity.TblMoveAndOut;
import com.stu.student_back_end.mapper.TblMoveAndOutMapper;
import com.stu.student_back_end.service.ITblMoveAndOutService;
import org.springframework.stereotype.Service;

/**
 * moveAndOut Service层实现类
 */
@Service
public class TblMoveAndOutServiceImpl extends ServiceImpl<TblMoveAndOutMapper, TblMoveAndOut> implements ITblMoveAndOutService {

    @Override
    public int saveMoveAndOut(TblMoveAndOut moveAndOutVo) {
        int insert = baseMapper.insert(moveAndOutVo);

        return insert;
    }

    @Override
    public Page<TblMoveAndOut> queryMoveAndOutPage(PageDTO pageDTO) {
        Page<TblMoveAndOut> page =new Page<>(pageDTO.getCurrentPage(),pageDTO.getSizePage());
        Page<TblMoveAndOut> moveAndOutPage = new Page<>();
        //判断是否带关键字
        if(!(pageDTO.getKeyWord() == "")) {
            //不为空
            moveAndOutPage = page(page, new LambdaQueryWrapper<TblMoveAndOut>().like(TblMoveAndOut::getStudentName, pageDTO.getKeyWord()));
        }else {
            moveAndOutPage = page(page);
        }
        return moveAndOutPage;
    }

    @Override
    public CountDTO queryMoveAndOutCount() {
        CountDTO countVo = new CountDTO();
        countVo.setName("迁入出记录");
        countVo.setCount(baseMapper.queryMoveAndOutCount());
        return countVo;
    }
}
